﻿namespace VirtualTemplates
{
    using System;
    using System.Collections;
    using System.Diagnostics.Contracts;
    using System.Web.Caching;
    using System.Web.Hosting;

    /// <summary>
    /// Defines functionality for a virtual template.
    /// </summary>
    [ContractClass(typeof(VirtualTemplateContract))]
    public interface IVirtualTemplate
    {
        /// <summary>
        /// Gets a value that indicates whether a file exists in the virtual file system.
        /// </summary>
        /// <param name="virtualPath">The path to the virtual file.</param>
        /// <returns>
        /// true if the file exists in the virtual file system; otherwise, false.
        /// </returns>
        bool FileExists(string virtualPath);

        /// <summary>
        /// Gets a virtual file from the virtual file system.
        /// </summary>
        /// <param name="virtualPath">The path to the virtual file.</param>
        /// <returns>
        /// A descendent of the <see cref="T:System.Web.Hosting.VirtualFile"/> class that represents a file in the virtual file system.
        /// </returns>
        VirtualFile GetFile(string virtualPath);

        /// <summary>
        /// Gets a value that indicates whether a directory exists in the virtual file system.
        /// </summary>
        /// <param name="virtualDir">The path to the virtual directory.</param>
        /// <returns>
        /// true if the directory exists in the virtual file system; otherwise, false.
        /// </returns>
        bool DirectoryExists(string virtualDir);

        /// <summary>
        /// Gets a virtual diretory from the virtual file system.
        /// </summary>
        /// <param name="virtualDir">The path to the virtual directory.</param>
        /// <returns>
        /// A descendent of the <see cref="T:System.Web.Hosting.VirtualDirectory"/> class that represents a directory in the virtual file system.
        /// </returns>
        VirtualDirectory GetDirectory(string virtualDir);

        /// <summary>
        /// Creates a cache dependency based on the specified virtual paths.
        /// </summary>
        /// <param name="virtualPath">The path to the primary virtual resource.</param>
        /// <param name="virtualPathDependencies">An array of paths to other resources required by the primary virtual resource.</param>
        /// <param name="utcStart">The UTC time at which the virtual resources were read.</param>
        /// <returns>
        /// A <see cref="T:System.Web.Caching.CacheDependency"/> object for the specified virtual resources.
        /// </returns>
        CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart);

        /// <summary>
        /// Returns a hash of the specified virtual paths.
        /// </summary>
        /// <param name="virtualPath">The path to the primary virtual resource.</param>
        /// <param name="virtualPathDependencies">An array of paths to other virtual resources required by the primary virtual resource.</param>
        /// <returns>
        /// A hash of the specified virtual paths.
        /// </returns>
        string GetFileHash(string virtualPath, IEnumerable virtualPathDependencies);
    }

    [ContractClassFor(typeof(IVirtualTemplate))]
    internal abstract class VirtualTemplateContract : IVirtualTemplate
    {
        public bool FileExists(string virtualPath)
        {
            Contract.Requires(virtualPath != null);

            throw new NotImplementedException();
        }

        public VirtualFile GetFile(string virtualPath)
        {
            Contract.Requires(virtualPath != null);

            throw new NotImplementedException();
        }

        public bool DirectoryExists(string virtualDir)
        {
            Contract.Requires(virtualDir != null);

            throw new NotImplementedException();
        }

        public VirtualDirectory GetDirectory(string virtualDir)
        {
            Contract.Requires(virtualDir != null);

            throw new NotImplementedException();
        }

        public CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
        {
            Contract.Requires(virtualPath != null);

            throw new NotImplementedException();
        }

        public string GetFileHash(string virtualPath, IEnumerable virtualPathDependencies)
        {
            Contract.Requires(virtualPath != null);
            Contract.Requires(virtualPathDependencies != null);

            throw new NotImplementedException();
        }
    }
}
